package com.campus.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.campus.common.annotation.Log;
import com.campus.common.core.controller.BaseController;
import com.campus.common.core.domain.AjaxResult;
import com.campus.common.enums.BusinessType;
import com.campus.manage.domain.Lost;
import com.campus.manage.service.ILostService;
import com.campus.common.utils.poi.ExcelUtil;
import com.campus.common.core.page.TableDataInfo;

/**
 * 失物招领Controller
 * 
 * @author hehe
 * @date 2025-10-22
 */
@RestController
@RequestMapping("/manage/lost")
public class LostController extends BaseController
{
    @Autowired
    private ILostService lostService;

    /**
     * 查询失物招领列表
     */
    @PreAuthorize("@ss.hasPermi('manage:lost:list')")
    @GetMapping("/list")
    public TableDataInfo list(Lost lost)
    {
        startPage();
        List<Lost> list = lostService.selectLostList(lost);
        return getDataTable(list);
    }

    /**
     * 导出失物招领列表
     */
    @PreAuthorize("@ss.hasPermi('manage:lost:export')")
    @Log(title = "失物招领", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Lost lost)
    {
        List<Lost> list = lostService.selectLostList(lost);
        ExcelUtil<Lost> util = new ExcelUtil<Lost>(Lost.class);
        util.exportExcel(response, list, "失物招领数据");
    }

    /**
     * 获取失物招领详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:lost:query')")
    @GetMapping(value = "/{lostId}")
    public AjaxResult getInfo(@PathVariable("lostId") Long lostId)
    {
        return success(lostService.selectLostByLostId(lostId));
    }

    /**
     * 新增失物招领
     */
    @PreAuthorize("@ss.hasPermi('manage:lost:add')")
    @Log(title = "失物招领", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Lost lost)
    {
        return toAjax(lostService.insertLost(lost));
    }

    /**
     * 修改失物招领
     */
    @PreAuthorize("@ss.hasPermi('manage:lost:edit')")
    @Log(title = "失物招领", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Lost lost)
    {
        return toAjax(lostService.updateLost(lost));
    }

    /**
     * 删除失物招领
     */
    @PreAuthorize("@ss.hasPermi('manage:lost:remove')")
    @Log(title = "失物招领", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lostIds}")
    public AjaxResult remove(@PathVariable Long[] lostIds)
    {
        return toAjax(lostService.deleteLostByLostIds(lostIds));
    }
}
